package com.zmn.oms.dubbo.impl.normal.master;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.oms.business.interfaces.master.MasterPartBService;
import com.zmn.oms.common.dro.normal.master.MasterPartInfoDRO;
import com.zmn.oms.common.dro.normal.master.MasterOrderPartInfoDRO;
import com.zmn.oms.common.dro.normal.master.OrderPartDetailDRO;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.dubbo.interfaces.normal.master.MasterPartListRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author sunlife
 * @date:2021/7/29 3:35 下午
 * description:
 */
@Slf4j
@Service(loadbalance = "roundrobin", timeout = 10000, retries = 0, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class MasterPartListRemoteServiceImpl implements MasterPartListRemoteService {
    @Autowired
    MasterPartBService masterPartBService;

    @Override
    public ResponseDTO<MasterPartInfoDRO> getMasterPartInfo(Integer masterId) {
        try {
            MasterPartInfoDRO masterPartInfoDRO = masterPartBService.getMasterPartInfo(masterId);
            return ResponseDTO.success(masterPartInfoDRO);
        } catch (OmsBaseException e) {
            log.error("获取师傅配件综合信息失败", e);
            return ResponseDTO.fromErrorCodeTable(e.getCode());
        } catch (Exception e) {
            log.error("获取师傅配件综合信息失败", e);
            return ResponseDTO.fail("获取师傅配件综合信息失败,请稍后重试");
        }
    }

    @Override
    public ResponseDTO<MasterOrderPartInfoDRO> listMonthPartInfo(Integer masterId, String date, Integer type) {
        try {
            MasterOrderPartInfoDRO masterPartInfoDRO = masterPartBService.listMonthPartInfo(masterId, date, type);
            return ResponseDTO.success(masterPartInfoDRO);
        } catch (OmsBaseException e) {
            log.error("获取师傅时间段配件信息失败", e);
            return ResponseDTO.fromErrorCodeTable(e.getCode());
        } catch (Exception e) {
            log.error("获取师傅时间段配件信息失败", e);
            return ResponseDTO.fail("获取师傅时间段配件信息失败,请稍后重试");
        }
    }

    @Override
    public ResponseDTO<OrderPartDetailDRO> getOrderPartDetail(Long orderId) {
        try {
            OrderPartDetailDRO  orderPartDetailDRO = masterPartBService.getOrderPartDetail(orderId);
            return ResponseDTO.success(orderPartDetailDRO);
        } catch (OmsBaseException e) {
            log.error("获取订单配件详情失败", e);
            return ResponseDTO.fromErrorCodeTable(e.getCode());
        } catch (Exception e) {
            log.error("获取订单配件详情失败", e);
            return ResponseDTO.fail("获取订单配件详情失败,请稍后重试");
        }
    }
}
